home *** CD-ROM | disk | FTP | other *** search
- /*
- Blasto
- A small program that blasts an 8 bit color icon to the screen.
- 3-6-92 By Brigham Stevens
- Apple Developer Technical Support
- 3-13-92 - BRS - Uh Oh, it's Friday the 13th
- Cleaned up & commented code here and there.
- 4-13-92 - BRS - changed icon to be self-erasing
- Made code somewhat better by changing names and stuff.
- Added comments
- 4-24-92 - BRS - Added ifdefs around timing code, changed names again.
- 11-11-92 - BRS - made a THINK C project file, and made this code work with
- THINK C. Also changed the date in the comment above.
- */
-
- /* Both Think C and MW C have precompiled headers.
- #ifndef THINK_C
- #include <OSUtils.h>
- #include <Windows.h>
- #include <QDOffscreen.h>
- #include <Retrace.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Events.h>
- #include <Menus.h>
- #endif*/
-
- #include "DirectScreen.h"
-
- void InitToolBox(short numMoreMasters);
-
- /* Amount to move icons these need to be around 1 or 2 */
- /* or our icon will not be self erasing */
- #define ROW_OFF 1
- #define COL_OFF 1
-
- #define MAX_SECONDS 100
-
- #ifndef THINK_C
- void ShowResult(long frameCount);
- long AverageTable(long *tab, short count);
- #endif
-
- void main()
- {
- WindowPtr directWindow;
- // GrafPort killMenuBar;
- Rect screenRect;
- GDHandle mainScreen;
- PixMapHandle mainscreenPixMap;
- Handle colorIconHandle;
- Point plotLocation;
- short vDelta = ROW_OFF;
- short hDelta = COL_OFF;
- long frameCount;
- // long *ticks = (long*)0x16A;
- long beforeTicks, afterTicks;
- // long tickTable[MAX_SECONDS];
- // short tickIndex = 0;
-
- long result;
- Str255 resultStr;
-
- /* Standard Witch Chant enclosed... */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitCursor();
- TEInit();
- FlushEvents(everyEvent, 0);
- InitDialogs(nil);
- MoreMasters();
- MoreMasters();
- MaxApplZone();
- // InitToolBox(4); /* 4 calls to MoreMasters */
-
- /* get a handle to the color icon we are drawing */
- colorIconHandle = GetResource('icl8',128);
- if(!colorIconHandle) {
- ParamText("\pBuild problems: 'icl8' not loaded.", "\p","\p","\p");
- Alert(128, nil);
- return;
- }
-
- /* cover up the part of the screen we are writing on */
- /* with a window, so other apps will not mess with our */
- /* animation via update events in the background */
- screenRect = qd.screenBits.bounds;
- directWindow = NewWindow(nil,&screenRect,nil,true,plainDBox,nil,false,0L);
-
- /* This covers up the menu bar */
- /* and fills the screen with white */
- SetPort(directWindow);
- RectRgn(directWindow->visRgn, &directWindow->portRect);
- EraseRect(&directWindow->portRect);
-
- /* get the main screen's Pix map */
- /* Which this program expects to be 8 bits deep */
- mainScreen = GetMainDevice();
- mainscreenPixMap = (**mainScreen).gdPMap;
-
- /* Set up a safe rectangle for bouncing off the screen */
- screenRect.top = 4;
- screenRect.left = 4;
- screenRect.bottom -= 32;
- screenRect.right -= 32;
-
- HideCursor();
-
- /* loop until the mouse is clicked */
- /* drawing and moving the color icon */
-
- /* This is where to start drawing the color icon*/
- plotLocation.h = 100;
- plotLocation.v = 100;
- frameCount = 0;
- beforeTicks = TickCount(); //*ticks;
-
- while (!Button()) {
- /* update the location of the icon */
- plotLocation.v += vDelta;
- plotLocation.h += hDelta;
- /* This forces us to stay on the screen and prevent bus errors */
- if(!PtInRect(plotLocation,&screenRect)) {
- vDelta = -vDelta; /* swap the deltas to bounce of corner */
- hDelta = -hDelta;
- }
-
- /* draw the icon */
-
- DirectPlotColorIcon((long *)*colorIconHandle,
- mainscreenPixMap, plotLocation.v, plotLocation.h);
- frameCount++;
- }
-
- /* show the average number of frames per second for MAX_SECONDS seconds */
- #ifndef THINK_C
- // ShowResult( AverageTable(tickTable,MAX_SECONDS) );
- #endif
- afterTicks = TickCount();
-
- ShowCursor();
-
- result = (frameCount * 60 / (afterTicks - beforeTicks));
- NumToString(result, resultStr);
- ParamText("\pFrames/sec:", resultStr, "\p", "\p");
- Alert(128, nil);
-
- CloseWindow(directWindow);
- DrawMenuBar();
- FlushEvents(mDownMask, 0);
- }